package presentation;

import javax.swing.*;



import presentation.ChampionnatInterface;
import java.awt.*;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.UnknownHostException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
import java.util.ResourceBundle;
/**
 * Class Ihm
 * Package presentation
 * Dfinition de la fenetre d'acceuil
 * 
 * @author Herv Le Fouler et Lionel Lasry
 */
public class Ihm {
	//La comboBox est publique pour tre modifie par le listener
	public 		JFrame fenetre = new JFrame("Championnats de foot : Acceuil");
	public 		JComboBox listeChampionnats = new JComboBox();
	public 		EcranLogin zoneCreationLogin = new EcranLogin();
	public		ZoneCreationChampionnat zoneCreationChampionnats  = new ZoneCreationChampionnat();
	public 		ZoneGestionChampionnats zoneGestionChampionnats  = new ZoneGestionChampionnats();
	public 		Locale local = Locale.getDefault();
	public 		ResourceBundle bundle = ResourceBundle.getBundle( "presentation/traduction", local);
	
	/**
	 * Class EcranLogin
	 * Package presentation
	 * Dfinition du JPanel d'identification
	 * Situ en haut dans l'IHM, pour l'utilisateur non identifi
	 * @author Herv Le Fouler et Lionel Lasry
	 */
	class EcranLogin extends JPanel{
		/**
		 * Constructeur de Ecranlogin
		 */
		public void Ecranlogin() {
			
		}
		/**
		 * Peuple la zone d'identification
		 * Ajoute les boutons de validation et d'annulation
		 * Ajoute les champs textes
		 * Assigne des Listeners aux boutons (ListenIdentification)
		 */
		public void addElementsEcranLogin(){
			JLabel labelLogin = new JLabel(bundle.getString("Login"));
			JTextField champLogin = new JTextField(15);
			JLabel labelMotDePasse = new JLabel(bundle.getString("Pass"));
			JTextField champMotDePasse = new JTextField(15);
			JButton validerIdentification = new JButton(bundle.getString("validation"));
			JButton annulerSaisieIdentification = new JButton(bundle.getString("annulation"));
			this.add(labelLogin);
			this.add(champLogin);
			this.add(labelMotDePasse);
			this.add(champMotDePasse);
			ListenIdentification monListener = new ListenIdentification(fenetre,champLogin,champMotDePasse,zoneCreationChampionnats,zoneGestionChampionnats,zoneCreationLogin);
			validerIdentification.addActionListener(monListener);
			annulerSaisieIdentification.addActionListener(monListener);
			this.add(validerIdentification);
			this.add(annulerSaisieIdentification);
		}
	}
	
	/**
	 * Class ZoneCreationChampionnat
	 * Package presentation
	 * Dfinition du JPanel de cration de championnat
	 * Situ en haut dans l'IHM,  condition d'tre identifi
	 * @author Herv Le Fouler et Lionel Lasry
	 */
	class ZoneCreationChampionnat extends JPanel{
		/**
		 * Constructeur de ZoneCreationChampionnat
		 */
		public ZoneCreationChampionnat() {
			
		}
		/**
		 * Peuple la zone de cration des championnats
		 * Ajoute le bouton de validation
		 * Ajoute le champ texte
		 * Assigne un Listener au bouton (ListenCreationChampionnat)
		 */
		public void addElementsZoneCreationChampionnat(){
			JTextField champCreationChampionnat = new JTextField(15);
			JButton validerCreationChampionnat = new JButton(bundle.getString("Creer_championnat"));
			//Ajout du listener de cration de championnat
			ListenCreationChampionnat monListener = new ListenCreationChampionnat(champCreationChampionnat,listeChampionnats);
			validerCreationChampionnat.addActionListener(monListener);
			this.add(champCreationChampionnat);
			this.add(validerCreationChampionnat);
		}
	}
	
	/**
	 * Class ZoneGestionChampionnats
	 * Package presentation
	 * Dfinition du JPanel de gestion des Championnats
	 * Situ en bas dans l'IHM,  condition d'tre identifi
	 * @author Herv Le Fouler et Lionel Lasry
	 */
	class ZoneGestionChampionnats extends JPanel{
		/**
		 * Constructeur de ZoneGestionChampionnats
		 */
		public ZoneGestionChampionnats(){

		}
		/**
		 * Peuple la zone de gestion des championnats
		 * Ajoute les boutons
		 * Ajoute la comboBox des championnats
		 * Remplit la comboBox des championnats
		 * Assigne les listeners aux diffrents boutons
		 * (ListenRefresh, ListenAjouterEquipes, ListenAjouterMatch, ListenClassement)
		 * Assigne un Listener au bouton (ListenCreationChampionnat)
		 */
		public void addElementsZoneGestionChampionnats(){
			JButton refresh = new JButton(bundle.getString("refresh_championnat"));
			JButton ajouterEquipes = new JButton(bundle.getString("ajouter_equipes"));
			JButton gererChampionnat = new JButton(bundle.getString("ajouter_matchs"));
			JButton voirClassementChampionnat = new JButton(bundle.getString("voir_classement"));
			//Ihm ihm = new Ihm();
			JComboBoxSql jcomboBoxSQL = new JComboBoxSql();
			jcomboBoxSQL.remplirComboBox(listeChampionnats);
			ListenRefresh monRefresh = new ListenRefresh(listeChampionnats);
			refresh.addActionListener(monRefresh);
			this.add(refresh);
			this.add(listeChampionnats);
			ListenAjouterEquipes monListener = new ListenAjouterEquipes(listeChampionnats);
			ajouterEquipes.addActionListener(monListener);
			this.add(ajouterEquipes);
			ListenAjouterMatch monListenerMatch = new ListenAjouterMatch(listeChampionnats);
			gererChampionnat.addActionListener(monListenerMatch);
			this.add(gererChampionnat);
			ListenClassement monListenerClassement = new ListenClassement(listeChampionnats);
			voirClassementChampionnat.addActionListener(monListenerClassement);
			this.add(voirClassementChampionnat);
		}
	}
	
	/**
	 * Peuple la fenetre
	 * Cration des instances des JPanel et lancement de leur mthodes de "remplissage"
	 */
	public void lancementEcranAcceuil (){

		zoneCreationLogin.addElementsEcranLogin();
		fenetre.add(zoneCreationLogin,BorderLayout.NORTH);
		
		zoneCreationChampionnats.addElementsZoneCreationChampionnat();
		if (zoneCreationChampionnats.isVisible()){
			zoneCreationChampionnats.setVisible(false);
		}
		fenetre.getContentPane().add(zoneCreationChampionnats,BorderLayout.CENTER);
		
		zoneGestionChampionnats.addElementsZoneGestionChampionnats();
		if (zoneGestionChampionnats.isVisible()){
			zoneGestionChampionnats.setVisible(false);
		}
		fenetre.getContentPane().add(zoneGestionChampionnats,BorderLayout.SOUTH);
		fenetre.pack();

		fenetre.setVisible(true);
		fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	public static void main (String [] args) throws UnknownHostException, MalformedURLException, RemoteException, NotBoundException{
		Ihm ihm = new Ihm();
		ihm.lancementEcranAcceuil ();
	}
}
